package ws.jonas.common;

public class Util {
	private Util() {
	}

	/**
	 * Returns {@code o1}.compareTo({@code o2}) in a null safe way. Considers null < !null.
	 */
	public static <T extends Comparable<? super T>> int compareNull(final T o1, final T o2) {
		if (o1 == null ^ o2 == null) {
			return o1 == null ? -1 : 1;
		}
		if (o1 == null && o2 == null) {
			return 0;
		}
		return o1.compareTo(o2);
	}
}
